<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>view/service/serviceLog/logEdit</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">

		<style type="text/css">
			.details_con{
				margin: 0; 
			}
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}

			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.sel{
				font-size: 12px;
				margin-left: 10px;
				color: #ffffff;
				background: #ea1e1a;
				height: 20px;
				line-height: 12px !important;
				margin-top: 16px;
				border-radius: 5px;
				padding: 5px;
			}
			.mui-btn-select{
				line-height: 3.125rem;
			}
			input.d_ipt {
			    float: right;
			    width: 65%;
			    border: 0;
			    height: 49px;
			    text-align: right;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">填写日志</h1>
		</header>
		<div class="mui-content">
			<div class="page_cen shadow title_num" id="dianji">服务通知编号：<span id="serviceNo1" style="color: #ea1e1a;"></span></div>
			<div class="details_con" id="form_info">
				<input type="hidden" name="id" id="id"/>
				<input type="hidden" name="fseId" id="fseId" />
				<input type="hidden" name="serviceNoticeId" id="serviceNoticeId" />
				<input type="hidden" name="serviceNo" id="serviceNo" />
				<div class="clum">
					<span class="name">接受任务时间</span>
					<input type="text" class="d_ipt" id="acceptTime" name="acceptTime" disabled="disabled"/>
				</div>
				<div class="clum">
					<span class="name">出发时间<em class="t_red">*</em></span>
					<input type="hidden" id="departureDay" />
					<input type="text" class="d_ipt" id="departureTime" name="departureTime" required="required" readonly="readonly" placeholder="请选择出发时间" />
				</div>
				<div class="clum">
					<span class="name">到达现场时间<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="arriveTime" name="arriveTime" required="required" readonly="readonly" placeholder="请选择到达现场时间" />
				</div>
				<div class="clum">
					<span class="name">工作开始时间<em class="t_red">*</em></span>
					<input type="hidden" id="startTimeDay" />
					<input type="text" class="d_ipt" id="startTime" name="startTime" required="required" readonly="readonly" placeholder="请选择工作开始时间" />
				</div>
				<div class="clum">
					<span class="name">工作结束时间<em class="t_red">*</em></span>
					<input type="hidden" id="endTimeDay" />
					<input type="text" class="d_ipt" id="endTime" name="endTime" required="required" readonly="readonly" placeholder="请选择工作结束时间" />
				</div>
				<div class="clum">
					<span class="name">工作小时数<em class="t_red">*</em></span>
					<input type="number" class="d_ipt" id="workHour" name="workHour" required="required" maxlength="4" placeholder="请输入工作小时数" />
				</div>
				<div class="clum">
					<span class="name">旅途小时数<em class="t_red">*</em></span>
					<input type="number" class="d_ipt" id="journeyHour" name="journeyHour" required="required" maxlength="4" placeholder="请输入旅途小时数" />
				</div>
				<div class="clum nobor autoHeight">
					<span class="name">工作内容<em class="t_red">*</em></span>
					<div class="clear"></div>
					<textarea class="textarea" id="workContent" name="workContent" required="required" maxlength="500" placeholder="请输入工作内容"></textarea>
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancelBtn">取消</span>
				<span class="fr red" id="submitBtn" style="display: none;">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script src="../../../js/fse/service/serviceLog/log.js"></script>

		
		<script type="text/javascript" charset="utf-8">
			var id;
			var sendTime;
			var pageName;
			var serviceNo;
			(function($, doc) {
				$.init();
		
				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					id = self.logId;
					sendTime = self.sendTime;
					pageName = self.pageName;

					// 获取接受任务时间（Send_time）、到达现场时间（on_site_data）
					getServiceTime();

					// 时间控件初始化
					initDateTimeControls()

					
					// 取消
					h('#cancelBtn').tap(function() {
						$.back();
					});
					
					// 提交保存
					h('#submitBtn').tap(function() {
						var d = h("#departureTime").val();
						var a = h("#arriveTime").val();
						var s = h("#startTime").val();
						var e = h("#endTime").val();
						var workHour = h("#workHour").val();
						var journeyHour = h("#journeyHour").val();
						var workContent = h("#workContent").val();
						if (!d) {
							app.toast("请选择出发时间");
							return false;
						}
						if (!s) {
							app.toast("请选择工作开始时间");
							return false;
						}
						if (!e) {
							app.toast("请选择工作结束时间");
							return false;
						}
						if (!workHour) {
							app.toast("请输入工作小时数");
							return false;
						}
						if (!journeyHour) {
							app.toast("请输入旅途小时数");
							return false;
						}
						if (!workContent) {
							app.toast("请输入工作内容");
							return false;
						}
						// var ddCheck = d.substring(0, d.indexOf(" ")).trim();
						// if (ddCheck != h("#departureDay").val()) {
						// 	app.toast("出发时间日期不可变更");
						// 	return false;
						// }
						// var sdCheck = s.substring(0, s.indexOf(" ")).trim();
						// if (sdCheck != h("#startTimeDay").val()) {
						// 	app.toast("工作开始时间日期不可变更");
						// 	return false;
						// }
						// var edCheck = e.substring(0, e.indexOf(" ")).trim();
						// if (edCheck != h("#endTimeDay").val()) {
						// 	app.toast("工作结束时间日期不可变更");
						// 	return false;
						// }
						// 时间关系校验
						var checkFlag = checkTimes();
						if (!checkFlag) {
							return false;
						}
						// 非负数校验
						var patt = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/
						if (patt.test(workHour) == false) {
							app.toast("请输入有效工作小时数");
							return false;
						}
						if (patt.test(journeyHour) == false) {
							app.toast("请输入有效旅途小时数");
							return false;
						}
						//POST参数对象
						var formObj = {
							"id" : id,
							"departureTime" : d,
							"arriveTime" : a ,
							"startTime" : s,
							"endTime" : e,
							"workHour" : workHour,
							"journeyHour" : journeyHour,
							"workContent" : workContent,
						};
						var newDate = new Date().getTime(); // 当前时间
						if (stringYYYYMMDDHHMMToDate(formObj.departureTime).getTime() > newDate) {
							app.toast('出发时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(formObj.arriveTime).getTime() > newDate) {
							app.toast('到达现场时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(formObj.startTime).getTime() > newDate) {
							app.toast('工作开始时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(formObj.endTime).getTime() > newDate) {
							app.toast('工作结束时间不能大于当前时间')
							return false
						}

						if(Number(workHour)>Number(gztimes)){
							app.toast("工作小时数，不能大于（工作结束时间-工作开始时间）");
							return false;
						}
						
						// 20200713 要求去掉这个判断
						/* if(Number(journeyHour)>Number(lttimes)){
							app.toast("旅途小时数，不能大于（到达现场时间-出发时间）");
							return false;
						} */
						
						app.showWaiting('加载中...');
						ajaxPost(BASE_URL + "cc/ServiceLog/editServiceLog", formObj, function(data) {
							app.closeWaiting()
							// console.log(JSON.stringify(data));
							if (data.code == 200) {//查询成功
								app.toast("保存成功");
								// 返回上一页并刷新
								var priorPage = plus.webview.getWebviewById('view/service/serviceLog/logList');
								if (pageName == "noticeLogList") {
									priorPage = plus.webview.getWebviewById('view/service/serviceLog/noticeLogList.html');
								}
								priorPage.evalJS('selectList()');
								self.close();
							} else {
								app.toast(data.msg);
							}
						}, function(errorMsg) {
							app.closeWaiting()
							app.toast(JSON.stringify(errorMsg))
						});
					});
				});
			}(mui, document));
			
			// 获取接受任务时间（Send_time）、到达现场时间（on_site_data）
			function getServiceTime() {
				if (sendTime) {
					sendTime = new Date(getUrlParam("sendTime")).Format("yyyy-MM-dd HH:mm")
				}
				if (id) {
					ajaxGet(BASE_URL + "cc/ServiceLog/selectServiceLogByID", {"id":id}, function(data) {
						// console.log(JSON.stringify(data));
						if (data.code == 200) {//查询成功
							var info = data.data;
							var reportId = info.reportId;
							var departureTime = info.departureTime;
							var startTime = info.startTime;
							var endTime = info.endTime;
							var dd = departureTime.substring(0, departureTime.indexOf(" ")).trim();
							var sd = startTime.substring(0, startTime.indexOf(" ")).trim();
							var ed = endTime.substring(0, endTime.indexOf(" ")).trim();
							serviceNo = info.serviceNo
							//alert(info.arriveTime);
							h("#acceptTime").val(info.acceptTime);
							h("#arriveTime").val(info.arriveTime);
							h("#departureTime").val(departureTime);
							h("#startTime").val(startTime);
							h("#endTime").val(endTime);
							h("#departureDay").val(dd);
							h("#startTimeDay").val(sd);
							h("#endTimeDay").val(ed);
							h("#workHour").val(info.workHour.toFixed(2));
							h("#journeyHour").val(info.journeyHour.toFixed(2));
							h("#workContent").val(info.workContent);
							h("#serviceNoticeId").val(info.serviceNoticeId);
							h("#serviceNo").val(info.serviceNo);
							h("#serviceNo").html(info.serviceNo);
							h("#serviceNo1").html(info.serviceNo);
							h("#id").val(id);
							jisuanChufaForEdit()
							jisuanKaishiForEdit()
							
							if (reportId) {
								h("#arriveTime").attr('disabled', 'disabled');
								h("#departureTime").attr('disabled', 'disabled');
								h("#startTime").attr('disabled', 'disabled');
								h("#endTime").attr('disabled', 'disabled');
								h("#workHour").attr('disabled', 'disabled');
								h("#journeyHour").attr('disabled', 'disabled');
								h("#workContent").attr('disabled', 'disabled');
								h("#submitBtn").hide();
							} else {
								h("#submitBtn").show();
							}
						} else {//查询失败
							app.toast("查询失败");
						}
					}, function(errorMsg) {
						console.log(JSON.stringify(errorMsg))
					});
				}
			}
			h("#dianji").tap(function(){
				app.jumpTo("/view/workArea/service/serveDetails.html", "view/workArea/service/serveDetails.html", {
					"serviceNo": serviceNo,
					"enginnerId": app.getUser().enginnerId
				})
			})
		</script>
		
		<!-- js代码 end -->

	</body>

</html>

